package com.fourth_groups.shopping121store.ui.person.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.fourth_groups.shopping121store.R;
import com.fourth_groups.shopping121store.bean.Person_horizontal;

import java.util.List;

/**
 * Created by Administrator on 2016/10/13.
 */

public class Grad_meadapter extends BaseAdapter{
    private LayoutInflater mInflater;
    private List<Person_horizontal> mdata;
    private Context mContext;
    public Grad_meadapter(Context context){
        this.mContext=context;
        mInflater=LayoutInflater.from(context);

    }
    public void setData(List<Person_horizontal>list){
        this.mdata=list;
        Log.i("t",list.toString());
        notifyDataSetChanged();

    }
    @Override
    public int getCount() {
        return mdata!=null?mdata.size():0;
    }

    @Override
    public Object getItem(int position) {
        return mdata!=null?mdata.get(position):0;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView==null){
            convertView=mInflater.inflate(R.layout.gridview_item,parent,false);
            holder=new ViewHolder(convertView);
            convertView.setTag(holder);
        }else {
            holder= (ViewHolder) convertView.getTag();
        }
        Person_horizontal horizontal=mdata.get(position);
        if (horizontal!=null){
            holder.grad_me.setText(horizontal.getTitle());
            Glide.with(parent.getContext()).load(horizontal.getIcon()).placeholder(R.mipmap.ic_launcher).centerCrop().into(holder.grad_pay);
        }



        return convertView;
    }
    class ViewHolder{
        ImageView grad_pay;
        TextView grad_me;
        public ViewHolder(View convertView){
            grad_pay= (ImageView) convertView.findViewById(R.id.grad_pay);
            grad_me = (TextView) convertView.findViewById(R.id.grad_me);
        }
    }
}
